<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!--<meta http-equiv="refresh" content="5">-->
<title>Insert title here</title>

		
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="/static/manage/common/bootstrap/js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
		
		<script type="text/javascript">
			
			//转换日期格式(时间戳转换为datetime格式)
			function changeDateFormat(cellval) {
				var dateVal = cellval + "";
				if(cellval != null) {
					var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
					var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
					var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

					var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
					var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
					var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

					return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
				}
			}

			function getURLParameter(name) { 
				return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; 
			}

			$(function() {

				var oTable = new TableInit();

				oTable.Init();

				var message = document.getElementById("message").value;

				if(message != null && message != "") {

					alert(message);

				}

			});
			var TableInit = function() {
				
				var oTableInit = new Object();
				//初始化Table
				oTableInit.Init = function() {

					$('#t').bootstrapTable({

						method: 'get',

						contentType: "application/x-www-form-urlencoded",

						url: "/sys/findDictionarysById?dic_index_id="+getURLParameter('dic_index_id'), //请求后台的URL（*）

						striped: true, //是否显示行间隔色

						locale: 'zh-CN', //中文支持

//						pagination: true, //是否开启分页（*）

//						pageNumber: 1, //初始化加载第一页，默认第一页

//						pageSize: 5, //每页的记录行数（*）
 
//						pageList: [3, 5, 7, 9], //可供选择的每页的行数（*）

						sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）

						//showRefresh: true, //刷新按钮

						queryParams: oTableInit.queryParams, //传递参数（*）

						strictSearch: true,

						//showColumns: true, //是否显示所有的列

						minimumCountColumns: 2, //最少允许的列数

						clickToSelect: true, //是否启用点击选中行

						columns: [{
								title: '<input type="checkbox" id="all" onclick="checkAll()"/>',
								align: 'center',
								width:'40',
								formatter: function (value, row, index) {
								    return '<input name="che" type="checkbox" value="'+row.dic_id+'"/>'
								}
							},{
								title: '',
								align: 'center',
								width:'40',
								formatter: function (value, row, index) {
								    //获取每页显示的数量
								    var pageSize=$('#t').bootstrapTable('getOptions').pageSize;  
								    //获取当前是第几页  
								    var pageNumber=$('#t').bootstrapTable('getOptions').pageNumber;
								    //返回序号，注意index是从0开始的，所以要加上1
								    return pageSize * (pageNumber - 1) + index + 1;
								}
							},{
								field: 'dic_code',
								title: '字典对照码',
								align: 'center'
							},{
								field: 'dic_value',
								title: '字典对照值',
								align: 'center'
							},
							{
								field: 'show_color',
								title: '显示颜色',
								align: 'center'
							}, {
								field: 'sort_no',
								title: '排序号',
								align: 'center'
							}, {
								field: 'status',
								title: '当前状态',
								align: 'center',
								formatter: function(v, r, i) {
									switch(Number(v)) {
										case 0:
											return "停用";
											break;
										case 1:
											return "启用";
											break;
									}
								}
							}, {
								field: 'edit_mode',
								title: '编辑模式',
								align: 'center',
								formatter: function(v, r, i) {
									switch(Number(v)) {
										case 0:
											return "只读";
											break;
										case 1:
											return "可编辑";
											break;
									}
								}
							}
						]

					});
					
				};

				//得到查询的参数

				oTableInit.queryParams = function(params) {

					var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的

						limit: params.limit, //页面大小

						offset: params.offset, //偏移量
						
						pageSize: params.limit, //页面大小
						
						dictionary:$("#dictionary").val()
						
					};
					return temp;
				};
				return oTableInit;
			};
			
			//模糊查询
			function chaxun () {
				$("#t").bootstrapTable('refresh');
				$("#dictionary").val("")
			}
			
			//全选
			function checkAll () {
				var allche = document.getElementById("all");
				var ches = document.getElementsByName("che");
				for (i = 0; i < ches.length; i++) {
					ches[i].checked = allche.checked;
				}
			}
			
			//获取选中的ids
			function findIds(ename) {
				arr = document.getElementsByName(ename);
				ids = [];
				for (k in arr) {
					if (arr[k].checked)
						ids.push(arr[k].value);
				}
				return ids;
			}
			
			//删除
			function del () {
				
				if (findIds("che").length!=0) {
					$.ajax({
						type:"get",
						url:"/sys/delDictionary?dic_ids="+findIds("che"),
						async:true,
						success:function (data) {
							if (data!=0) {
								alert("删除成功！！！")
								$("#t").bootstrapTable('refresh');
							} else{
								alert("删除失败！！！")
							}
						}
					});
					
				} else {
					alert("你未选择要删除的数据！！！")
				}				
			}
			
			//获取字典标识和名称
			$.ajax({
				type:"get",
				url:"/sys/findDictionaryIndexById?dic_index_id="+getURLParameter('dic_index_id'),
				async:true,
				success:function (data) {
					$("#dic_key").val(data.dic_key)
					$("#dic_name").val(data.dic_name)
					$("#dic_key1").val(data.dic_key)
					$("#dic_name1").val(data.dic_name)
				}
			});
			
			//添加按钮
			function add () {
				$("#myModal").modal("show")
			}
			
			//用户添加
			function addDictionary () {
				$("#dic_index_id").val(getURLParameter('dic_index_id'))
				$.ajax({
					type:"post",
					url:"/sys/addDictionary",
					data:$("#addForm").serialize(),
					success:function (msg) {
						if (msg!=0) {
							alert("添加成功！！")
							$("#myModal").modal("hide")
							location.reload()
							$("#t").bootstrapTable('refresh')
						} else{
							alert("添加失败！！")
						}
					}
					
				});
			}
			
			//修改按钮
			function upd () {
				if (findIds("che").length==1) {
						$.ajax({
						type:"post",
						url:"/sys/findDictionaryById?dic_id="+findIds("che"),
						async:true,
						success:function (data) {
							$("#myModal1").modal("show");
							$("#dic_id1").val(data.dic_id);
							$("#dic_index_id1").val(data.dic_index_id)
							$("#dic_code1").val(data.dic_code);
							$("#dic_value1").val(data.dic_value);
							$("#show_color1").val(data.show_color);
							$("#status1").val(data.status);
							$("#edit_mode").val(data.edit_mode);
							$("#sort_no1").val(data.sort_no);
						}
					});
				}else if (findIds("che").length>1) {
					alert("一次只可修改一条数据哟！！！")
				}else{
					alert("你未选择要修改的数据！！！")
				}	
				
			}
			
			//修改菜单
			function updDictionary () {
				$.ajax({
					type:"post",
					url:"/sys/updDictionary",
					data:$("#updForm").serialize(),
					success:function (msg) {
						if (msg!=0) {
							alert("修改成功！！")
							$("#myModal1").modal("hide")
							$("#t").bootstrapTable('refresh')
						} else{
							alert("修改失败！！")
						}
					}
				});
			}
		</script>
</head>
<body>
			<form class="form-inline">
				<div class="form-group">
					<input type="text" class="form-control" id="dictionary" name="dictionary" placeholder="字典对照码或字典对照值">
				</div>
				<button type="button" class="btn btn-default" onclick="chaxun()"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
			</form>
	
			<table id="t">
				<div class="inline">
					<button id="add" onclick="add()" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus" style="color: green;" aria-hidden="true"></span>新增</button>
					<button id="upd" onclick="upd()" type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil" style="color: green;" aria-hidden="true"></span>修改</button>
					<button id="del" onclick="del()" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除</button>
				</div>
			</table>
	
	<!--添加的模态框-->
		<!-- Modal -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 900px; height: 1500px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">新增字典</h4>
					</div>
					<div class="modal-body">
						 
						<!--添加form表单-->
						<form id="addForm">
							<input type="hidden" id="dic_index_id" name="dic_index_id" />
							<div class="modal-body">
								<div class="form-group"><!--用户账号-->
									<label for="dic_key" class="col-sm-3 control-label">字典标识:</label>
									<div class="col-sm-3">
										<input type="text" disabled="disabled" class="form-control" id="dic_key" name="dic_key" placeholder="Dic_key">
									</div>
									<label for="dic_name" class="col-sm-3 control-label">字典名称:</label>
									<div class="col-sm-3">
										<input type="text" disabled="disabled" class="form-control" id="dic_name" name="dic_name" placeholder="Dic_name">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group"><!--用户账号-->
									<label for="dic_code" class="col-sm-3 control-label">字典对照码:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="dic_code" placeholder="Dic_code">
									</div>
									<label for="dic_value" class="col-sm-3 control-label">字典对照值:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="dic_value" placeholder="Dic_value">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="show_color" class="col-sm-3 control-label">显示颜色:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" name="show_color" placeholder="Show_color">
									</div>
									<label for="sort_no" class="col-sm-3 control-label">排序号：</label>
									<div class="col-sm-3">
										<input type="number" class="form-control" name="sort_no" placeholder="Sort_no">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="status" class="col-sm-3 control-label">当前状态:</label>
									<div class="col-sm-3">
										<select class="form-control" name="status">
											<option value="0">停用</option>
											<option value="1">启用</option>
										</select>
									</div>
									<label for="edit_mode" class="col-sm-3 control-label">编辑模式：</label>
									<div class="col-sm-3">
										<select class="form-control" name="edit_mode">
											<option value="0">只读</option>
											<option value="1">可编辑</option>
										</select>
									</div>
								</div>
							</div>
							
							
						</form>
						
					</div>
					<div>
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						<button type="button" class="btn btn-primary" onclick="addDictionary()">Add</button>
					</div>
				</div>
			</div>
		</div>
		
		
		<!--修改的模态框-->
		<!-- Modal -->
		<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 900px; height: 1500px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">修改字典</h4>
					</div>
					<div class="modal-body">
						 
						<!--修改form表单-->
						<form id="updForm">
							<input type="hidden" id="dic_id1" name="dic_id" />
							<input type="hidden" id="dic_index_id1" name="dic_index_id" />
							<div class="modal-body">
								<div class="form-group"><!--用户账号-->
									<label for="dic_key" class="col-sm-3 control-label">字典标识:</label>
									<div class="col-sm-3">
										<input type="text" disabled="disabled" class="form-control" id="dic_key1" name="dic_key" placeholder="Dic_key">
									</div>
									<label for="dic_name" class="col-sm-3 control-label">字典名称:</label>
									<div class="col-sm-3">
										<input type="text" disabled="disabled" class="form-control" id="dic_name1" name="dic_name" placeholder="Dic_name">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group"><!--用户账号-->
									<label for="dic_code" class="col-sm-3 control-label">字典对照码:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="dic_code1" name="dic_code" placeholder="Dic_code">
									</div>
									<label for="dic_value" class="col-sm-3 control-label">字典对照值:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="dic_value1" name="dic_value" placeholder="Dic_value">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="show_color" class="col-sm-3 control-label">显示颜色:</label>
									<div class="col-sm-3">
										<input type="text" class="form-control" id="show_color1" name="show_color" placeholder="Show_color">
									</div>
									<label for="sort_no" class="col-sm-3 control-label">排序号：</label>
									<div class="col-sm-3">
										<input type="number" class="form-control" id="sort_no1" name="sort_no" placeholder="Sort_no">
									</div>
								</div>
							</div>
							
							<div class="modal-body">
								<div class="form-group">
									<label for="status" class="col-sm-3 control-label">当前状态:</label>
									<div class="col-sm-3">
										<select class="form-control" id="status1" name="status">
											<option value="0">停用</option>
											<option value="1">启用</option>
										</select>
									</div>
									<label for="edit_mode" class="col-sm-3 control-label">编辑模式：</label>
									<div class="col-sm-3">
										<select class="form-control" id="edit_mode1" name="edit_mode">
											<option value="0">只读</option>
											<option value="1">可编辑</option>
										</select>
									</div>
								</div>
							</div>
							
						</form>
						
					</div>
					<div>
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						<button type="button" class="btn btn-primary" onclick="updDictionary()">Update</button>
					</div>
				</div>
			</div>
		</div>
</body>
</html>